package cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpitemwsl;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpitemwsl.vo.DpItemWslPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpitemwsl.vo.DpItemWslRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpitemwsl.vo.DpItemWslSaveReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.dpitem.DpItemWslDO;
import cn.iocoder.yudao.module.erp.service.dpitem.DpItemWslService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import javax.servlet.http.*;
import java.io.IOException;
import java.util.List;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;


@Tag(name = "管理后台 - ERP乌苏里制单货号详情")
@RestController
@RequestMapping("/erp/dp-item-wsl")
@Validated
public class DpItemWslController {

    @Resource
    private DpItemWslService dpItemWslService;

    @PostMapping("/create")
    @Operation(summary = "创建ERP乌苏里制单货号详情")
    // @PreAuthorize("@ss.hasPermission('erp:dp-item-wsl:create')")
    public CommonResult<Long> createDpItemWsl(@Valid @RequestBody DpItemWslSaveReqVO createReqVO) {
        return success(dpItemWslService.createDpItemWsl(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新ERP乌苏里制单货号详情")
    // @PreAuthorize("@ss.hasPermission('erp:dp-item-wsl:update')")
    public CommonResult<Boolean> updateDpItemWsl(@Valid @RequestBody DpItemWslSaveReqVO updateReqVO) {
        dpItemWslService.updateDpItemWsl(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除ERP乌苏里制单货号详情")
    @Parameter(name = "id", description = "编号", required = true)
    // @PreAuthorize("@ss.hasPermission('erp:dp-item-wsl:delete')")
    public CommonResult<Boolean> deleteDpItemWsl(@RequestParam("id") Long id) {
        dpItemWslService.deleteDpItemWsl(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得ERP乌苏里制单货号详情")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    // @PreAuthorize("@ss.hasPermission('erp:dp-item-wsl:query')")
    public CommonResult<DpItemWslRespVO> getDpItemWsl(@RequestParam("id") Long id) {
        DpItemWslDO dpItemWsl = dpItemWslService.getDpItemWsl(id);
        return success(BeanUtils.toBean(dpItemWsl, DpItemWslRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得ERP乌苏里制单货号详情分页")
    // @PreAuthorize("@ss.hasPermission('erp:dp-item-wsl:query')")
    public CommonResult<PageResult<DpItemWslRespVO>> getDpItemWslPage(@Valid DpItemWslPageReqVO pageReqVO) {
        PageResult<DpItemWslDO> pageResult = dpItemWslService.getDpItemWslPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, DpItemWslRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出ERP乌苏里制单货号详情 Excel")
    // @PreAuthorize("@ss.hasPermission('erp:dp-item-wsl:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportDpItemWslExcel(@Valid DpItemWslPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<DpItemWslDO> list = dpItemWslService.getDpItemWslPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "ERP乌苏里制单货号详情.xls", "数据", DpItemWslRespVO.class,
                        BeanUtils.toBean(list, DpItemWslRespVO.class));
    }

}